export default{
	async getNewsList() {
		let requestUrl = "information/inforPage";
		if(this.type == 0) {
			requestUrl = "notice/noticePage"; //公告中心
		} else if(this.type == 1) {
			requestUrl = "information/inforPage"; //资讯
		} else if(this.type == 2) {
			requestUrl = "receptionroom/loungePage"; //会客厅
		}else if(this.type == 3) {
			requestUrl = "crudeoil/page"; //原油宝典
		}
		
		let res = await this.httptool.post(requestUrl, this.params);
		this.total = res.data.total;
		this.tableData = res.data.list.map(item=>{
			if(item.articleContent){
				item.articleContent = item.articleContent.replace(/<[^>]+>|&nbsp;/g, "");
				return item;
			}
		});
	},
	async getNewsDetail() {
		let requestUrl = "notice/get";
		let type = this.type;
		if(type == 0) {
			requestUrl = "notice/get"; //公告中心
		} else if(type == 1) {
			requestUrl = "information/get"; //资讯
		} else if(type == 2) {
			requestUrl = "receptionroom/articlebyid"; //会客厅
		}else if(type == 3) {
			requestUrl = "crudeoil/articlebyid"; //原油宝典
		}
		let res = await this.httptool.post(requestUrl, {id:this.id});
		this.modelData = res.data;
	},
	async getNewsCommentsPage() {
		if(this.pageNum!=1 && this.total&&this.tableData.length>=this.total){
			return;
		}
		let params = {
			articleId: this.id,
			pageNum: this.pageNum,
			pageSize: 10
		};		
		let res = await this.httptool.post('articleComment/articlePage', params);
		if(this.pageNum==1){
			this.tableData = res.data.list;	
		}else{
			this.tableData = this.tableData.concat(res.data.list);
		}
		
		this.total = res.data.total;
		this.pageNum++;
	},
	async sendComments() {
		this.params.articleId = this.id;
		let params = this.params;
		
		if(!params.articleCommentContent) {
			this.$message('回复内容不能为空！');
			return;
		}
		console.log(this.$store.state.userInfo);
		if(!this.$store.state.userInfo || !this.$store.state.userInfo.id){
			this.$router.push('/login');
			return;
		}
		await  this.httptool.post('articleComment/addArticle', params);
		this.pageNum = 1;
		this.getNewsCommentsPage();		
		this.reset();		
		this.$message.success('评论成功!');
	}
}